<?php
include_once 'inc/config.inc.php';
include_once 'inc/mysql.inc.php';
include_once 'inc/tool.inc.php';

$template["title"] = "用户注册";

$link = connect();

if(is_login($link)){
    skip("index.php", "error", "你已经登录，请不要重复注册！");
}

if(isset($_POST['submit'])){
    // 验证操作
    include_once 'inc/check_register.inc.php';

    $query = "insert into kuse_member(name, pw, register_time) values('{$_POST['name']}', md5('{$_POST['pw']}'), now())";
    execute($link, $query);
    if(mysqli_affected_rows($link)){
        setcookie('kuse[name]', $_POST['name']);
        setcookie('kuse[pw]', md5($_POST['pw']));
        skip("index.php", "ok", "注册成功！");
    }else{
        skip("index.php", "error", "注册失败！");
    }
}
?>
<?php include_once 'inc/header.inc.php'; ?>

    <!-- 主体代码开始 -->
    <div class="register content-box">
        <h2>欢迎注册成为 苦涩BBS会员</h2>
        <form class="clearfix" method="post">
            <label>用户名：<input type="text" name="name"><span>*用户名不得为空，并且长度不得超过32个字符</span></label>
            <label>密码：<input type="password" name="pw"><span>*密码不得少于6位</span></label>
            <label>确认密码：<input type="password" name="confirm_pw"><span>*请输入与上面一致密码</span></label>
            <label>验证码：<input type="text" name="vcode"><span>请输入下方验证码</span></label>
            <img src="show_code.php" class="vcode">
            <div style="clear:both;"></div>
            <input class="btn" name="submit" type="submit" value="确认注册">
        </form>
    </div>
    <!-- 主体代码结束 -->

<?php include_once 'inc/footer.inc.php'; ?>
